﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Threading;

public class SynchronValue
{
   // private int syn = 0;//同步变量
    private object syn = new object();
    private int i = 8;

    public HttpResponse Resp { get; set; }//输出内容的对象

    public void DoWork(object state)
    {
        Monitor.Enter(syn);//使用值类型对象同步  P操作
        Resp.Write("i的值为:" + i.ToString() + "<br/>");
        i++;
        //模拟其它的工作
        Thread.Sleep(100);
        Resp.Write("i自增1后的值为:" + i.ToString() + "<br/>");
        Monitor.Exit(syn);//移除同步  V操作
    }
}
